package cn.ronghuanet.auth.controller;

import cn.ronghuanet.auth.domain.Menu;
import cn.ronghuanet.auth.service.IMenuService;
import cn.ronghuanet.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    /**
     * 获取当前登录用户的菜单
     * 怎么获取当前登录用户?
     * 方式一:前端传
     * 方式二:后端自己获取当前登录用户
     * @return
     */
    @GetMapping("/tree/{loginUserId}")
    public AjaxResult tree(@PathVariable("loginUserId") Long loginUserId){
        try {
            List<Menu> menus = menuService.tree(loginUserId);
            return AjaxResult.me().setResultObj(menus);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取菜单失败!"+e.getMessage());
        }
    }

}
